﻿//using System.Data;

//namespace Marmat.Data
//{
//    public class Vars
//    {
//        public static string Get(string VarName)
//        {
//            string Result = null;
//            var dt = Get("UserConfiguration", VarName);
//            if (dt is object && dt.Rows.Count > 0)
//            {
//                Result = dt.Rows[0]["Content"].ToString();
//            }

//            return Result;
//        }

//        internal static DataTable Get(string TypeName, string VarName)
//        {
//            if (string.IsNullOrEmpty(Configuration.ConfigurationConnectionString))
//            {
//                Configuration.SetConfiguration(null, null);
//            }

//            var dt = new DataTable();
//            using (var OleDbConnection = new System.Data.OleDb.OleDbConnection(Configuration.ConfigurationConnectionString))
//            {
//                if (OleDbConnection.State != ConnectionState.Open)
//                    OleDbConnection.Open();
//                using (var adapter = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + TypeName + "] WHERE [Key] = '" + VarName + "'", OleDbConnection))
//                {
//                    adapter.Fill(dt);
//                }

//                if (OleDbConnection.State != ConnectionState.Closed)
//                    OleDbConnection.Close();
//            }

//            return dt;
//        }

//        public static void Set(string VarName, string Value)
//        {
//            Set("UserConfiguration", VarName, Value);
//        }

//        internal static void Set(string TypeName, string VarName, string Value)
//        {
//            if (string.IsNullOrEmpty(Configuration.ConfigurationConnectionString))
//            {
//                Configuration.SetConfiguration(null, null);
//            }

//            using (var OleDbConnection = new System.Data.OleDb.OleDbConnection(Configuration.ConfigurationConnectionString))
//            {
//                if (OleDbConnection.State != ConnectionState.Open)
//                    OleDbConnection.Open();
//                var cmd = new System.Data.OleDb.OleDbCommand("", OleDbConnection);
//                switch (TypeName ?? "")
//                {
//                    case "Configuration":
//                        {
//                            cmd.CommandText = "Insert Into [" + TypeName + "] ([Key],[Content]) Values('" + VarName + "','" + Value + "')";
//                            cmd.ExecuteNonQuery();
//                            break;
//                        }

//                    case "UserConfiguration":
//                        {
//                            cmd.CommandText = "UPDATE [" + TypeName + "] SET [Content] = '" + Value + "' WHERE [Key] = '" + VarName + "'";
//                            if (cmd.ExecuteNonQuery() == 0)
//                            {
//                                cmd.CommandText = "Insert Into [" + TypeName + "] ([Key],[Content]) Values('" + VarName + "','" + Value + "')";
//                                cmd.ExecuteNonQuery();
//                            }

//                            break;
//                        }
//                }

//                if (OleDbConnection.State != ConnectionState.Closed)
//                    OleDbConnection.Close();
//            }
//        }
//    }
//}